Free command encoders' platform resources on drop on _all_ platforms #5251
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Connections
Link to the issues addressed by this PR, or dependent PRs in other repositories
This is my attempt to investigate and resolve #3193.
I believe this code is ready to go, but have not yet confirmed internal details to my satisfaction. I'm leaving this as WIP for now because I will be unavailable to work on finalizing details until ~2024-02-21. If somebody wants to pick it up before then, great!Description
Describe what problem this is solving, and how it's solved.
I believe that #3193 is caused by not freeing command encoders early enough. This is apparent on the DX12 backend, where the DX12 API actually emits an error to inform us of our mistake. This is likely causing issues in other backends (i.e., Vulkan), where the symptoms aren't as obvious. Metal has already been cared for by @bradwerth with #2077, so only the other backends need attention here.
Interestingly, we don't currently do any clean-up of command encoders when they are dropped, but we do when they're
finish
ed. This seems wrong. So, this change adds aCommandEncoder::discard_encoding
call for command encoders withinwgpu_core::Global::command_encoder_drop
. This change also adds a similar call to theDrop
implementation of backends that appear to be idempotent in theirCommandEncoder::discard_encoder
calls (N.B., this does not include Vulkan). This appears to resolve DX12 API errors.To be completely clear about how each backend is changed here:
Testing
Explain how this change is tested.
A test (wgpu_test::buffer::command_encoder_without_finish_fine
) has been added, demonstrating both the expected failure before the fix and resolution to "just" passing.This change changes numerous expected error cases for tests for
DX12
, most notablywgpu_tests::encoder::drop_encoder_after_error
, to simply be passing.Checklist
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.